package com.proj.rest.resource;

import com.proj.beans.User;
import com.proj.core.ServiceFactory;
import com.proj.service.UserService;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

@Path("/user")
@Produces(MediaType.APPLICATION_JSON)
public final class UserResource
{
    private UserService userService;

    @Path("{id}")
    @GET
    public User getUser(@PathParam("id") String userName)
    {
        return userService.getUser(userName);
    }

    @POST
    @Consumes({MediaType.APPLICATION_JSON})
    public void addUser(User user)
    {
        long id = userService.createUser(user);
        System.out.println("id = " + id);
    }

    @POST
    @Path("{userId}")
    @Consumes({MediaType.APPLICATION_JSON})
    public void updateUser(@PathParam("userId") String userId, User user)
    {
        System.out.println("userId = " + userId);
        userService.updateUser(userId, user);
    }

    @DELETE
    @Path("{userId}")
    public void deleteUser(@PathParam("userId") String userName)
    {
        userService.deleteUser(userName);
    }

    public void setUserService(UserService userService)
    {
        this.userService = userService;
    }
}
